package com.kt.uokos.yimo.controller;

import com.kt.uokos.yimo.anno.validator.Order;
import com.kt.uokos.yimo.anno.validator.Sort;
import com.kt.uokos.yimo.dao.SearchHistory;
import com.kt.uokos.yimo.service.SearchHistoryService;
import com.kt.uokos.yimo.util.ResponseUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/history")
public class SearchHistoryController {

    @Resource
    private SearchHistoryService searchHistoryService;


    @GetMapping("/list")
    public Object list(String userId, String keyword,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order){
        List<SearchHistory> searchHistories = searchHistoryService.querySelective(userId, keyword, page, limit, sort, order);

        return ResponseUtil.okList(searchHistories);
    }

}
